package com.ysx.behaviour.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ysx.behaviour.dto.LikesBehaviourDto;
import com.ysx.behaviour.pojo.ApLikesBehavior;
import com.ysx.behaviour.service.ApLikesBehaviorService;
import com.ysx.common.pojo.Result;
import com.ysx.core.controller.AbstractCoreController;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* <p>
* APP点赞行为表 控制器</p>
* @author ljh
* @since 2021-10-07
*/
@Api(value="APP点赞行为表",tags = "ApLikesBehaviorController")
@RestController
@RequestMapping("/apLikesBehavior")
public class ApLikesBehaviorController extends AbstractCoreController<ApLikesBehavior> {

    private ApLikesBehaviorService apLikesBehaviorService;

    //注入
    @Autowired
    public ApLikesBehaviorController(ApLikesBehaviorService apLikesBehaviorService) {
        super(apLikesBehaviorService);
        this.apLikesBehaviorService=apLikesBehaviorService;
    }

    @PostMapping("/like")
    public Result like(@RequestBody LikesBehaviourDto likesBehaviourDto) throws Exception{
        apLikesBehaviorService.like(likesBehaviourDto);
        return Result.ok();
    }

    /**
     * 根据文章的ID 和 entryId获取 是否点赞
     * @param articleId
     * @param entryId
     * @return
     */
    @GetMapping("/getLikesBehavior")
    public ApLikesBehavior getLikesBehavior(@RequestParam(name="articleId") Long articleId, @RequestParam(name="entryId")Integer entryId) {
        //创建条件构造器
        QueryWrapper<ApLikesBehavior> apLikesBehaviorQueryWrapper = new QueryWrapper<>();
        apLikesBehaviorQueryWrapper.eq("article_id", articleId);
        apLikesBehaviorQueryWrapper.eq("entry_id", entryId);
        //查询
        return apLikesBehaviorService.getOne(apLikesBehaviorQueryWrapper);
    }
}

